package cn.element.io.nio.case1;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class IServerPool {

    // 1.创建一个线程池的成员变量
    private final ExecutorService executorService;

    /**
     * public ThreadPoolExecutor(int corePoolSize,
     *                               int maximumPoolSize,
     *                               long keepAliveTime,
     *                               TimeUnit unit,
     *                               BlockingQueue<Runnable> workQueue)
     */
    public IServerPool(int maxNum, int queueSize) {
        executorService = new ThreadPoolExecutor(
                3,
                maxNum,
                120,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(queueSize)
        );
    }

    public void execute(Runnable target) {
        executorService.execute(target);
    }


}
